import java.util.*;

/**
 * @author agstar
 * @date 2020/5/6 23:25
 */
public class ValidParentheses {

    public static void main(String[] args) {
        String str = "[[(())]]";
        boolean valid = isValid(str);
        System.out.println(valid);
    }

    public static boolean isValid(String s) {
        Stack<Character> stack = new Stack<>();
        HashMap<Character, Character> map = new HashMap<>();
        map.put(')', '(');
        map.put(']', '[');
        map.put('}', '{');
        char[] chars = s.toCharArray();
        for (int i = 0; i < chars.length; i++) {
            Character aChar = chars[i];
            if (!map.containsKey(aChar)) {
                stack.push(aChar);
            } else if (stack.isEmpty() || !map.get(aChar).equals(stack.pop())) {
                return false;
            }
        }
        return stack.isEmpty();
    }

}
